package com.scommunity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scommunity.admin.vo.BuildingQO;
import com.scommunity.domain.Building;
import com.scommunity.mapper.BuildingMapper;
import com.scommunity.service.IBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements IBuildingService {
    @Autowired
    BuildingMapper buildingMapper;

    @Override
    public PageInfo<Building> findPageInfoByCondition(BuildingQO buildingQO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Building> buildings = buildingMapper.findPageInfoByCondition(buildingQO);
        PageInfo<Building> pageInfo = new PageInfo<>(buildings);
        return pageInfo;
    }

    @Cacheable(value = "buildings")
    @Override
    public List<Building> getAll() {
        return buildingMapper.findAll();
    }

    @Override
    public List<Building> getAllByStatus() {
        return buildingMapper.getAllByStatus();
    }

    @CacheEvict(value = "buildings", allEntries = true)
    @Override
    public void add(Building building) {
        buildingMapper.add(building);
    }

    @CacheEvict(value = "buildings", allEntries = true)
    @Override
    public void update(Building building) {
        buildingMapper.update1(building);
    }

    @CacheEvict(value = "buildings", allEntries = true)
    @Override
    public void del(String id) {
        buildingMapper.del(id);
    }

    @Override
    public int getStatuseById(String id) {
        return buildingMapper.getStatuseById(id);
    }
}
